package com.ruoyi.receive.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.receive.domain.SimReceive;
import com.ruoyi.receive.service.ISimReceiveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 领用管理Controller
 * 
 * @author laifolai
 * @date 2023-02-07
 */
@RestController
@RequestMapping("/receive/manage")
public class SimReceiveController extends BaseController
{
    @Autowired
    private ISimReceiveService simReceiveService;

    /**
     * 查询领用管理列表
     */
    @PreAuthorize("@ss.hasPermi('receive:manage:list')")
    @GetMapping("/list")
    public TableDataInfo list(SimReceive simReceive)
    {
        startPage();
        List<SimReceive> list = simReceiveService.selectSimReceiveList(simReceive);
        return getDataTable(list);
    }

    /**
     * 导出领用管理列表
     */
    @PreAuthorize("@ss.hasPermi('receive:manage:export')")
    @Log(title = "领用管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SimReceive simReceive)
    {
        List<SimReceive> list = simReceiveService.selectSimReceiveList(simReceive);
        ExcelUtil<SimReceive> util = new ExcelUtil<SimReceive>(SimReceive.class);
        util.exportExcel(response, list, "领用管理数据");
    }

    /**
     * 获取领用管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('receive:manage:query')")
    @GetMapping(value = "/{receiveId}")
    public AjaxResult getInfo(@PathVariable("receiveId") Long receiveId)
    {
        return AjaxResult.success(simReceiveService.selectSimReceiveByReceiveId(receiveId));
    }

    /**
     * 新增领用管理
     */
    @PreAuthorize("@ss.hasPermi('receive:manage:add')")
    @Log(title = "领用管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SimReceive simReceive)
    {
        return toAjax(simReceiveService.insertSimReceive(simReceive));
    }

    /**
     * 修改领用管理
     */
    @PreAuthorize("@ss.hasPermi('receive:manage:edit')")
    @Log(title = "领用管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SimReceive simReceive)
    {
        return toAjax(simReceiveService.updateSimReceive(simReceive));
    }

    /**
     * 删除领用管理
     */
    @PreAuthorize("@ss.hasPermi('receive:manage:remove')")
    @Log(title = "领用管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{receiveIds}")
    public AjaxResult remove(@PathVariable Long[] receiveIds)
    {
        return toAjax(simReceiveService.deleteSimReceiveByReceiveIds(receiveIds));
    }
}
